<?php
// +--------------------------------------------------------------------------
// | ZAIYOUDAO [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2016 载攸道 版权所有 <TEL:17090888854>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * Mall
 */
namespace Mall\Controller;
use Common\Controller\AdminController;
Vendor('Qiniusdk.autoload'); //七牛入口文件引入 
use Qiniu\Auth; 
use Qiniu\Storage\UploadManager;
use Think\Upload;
use Qiniu\Processing\PersistentFop;
/**
 * 页面
 */
class UserController extends AdminController{
	
	
	#专辑试听转码
	public function type_zhuanma_shiting($type,$result,$url){
		$m_mall_content_music = M("mall_content_music");
		#$type = 4;
		$this->upload_video_shiting($url);
		$music_add['type'] = $type;
		$music_add['form_id'] = $result;
		$name_array = explode(".",$url);
		$music_add['url'] = "http://p7j34hu3o.bkt.clouddn.com/".$name_array[0]."_s.mp3";
		$m_mall_content_music->add($music_add);
	}
	
	
	public function upload_video_shiting($key) {
		$accessKey = "8sc_uncdqBnQUYyWViRALobZH33YO_lZKD65Y04a";
		$secretKey = "FczTgs6OmHBb7jke7pExGeujvxIHXO0trUCIbmBE";
		$bucket = "music";
		$auth = new Auth($accessKey, $secretKey);
		//要转码的文件所在的空间和文件名。
		#$key = '1527143791383.flac';
		//转码是使用的队列名称。 https://portal.qiniu.com/mps/pipeline   1527231255422.flac
		$pipeline = 'music_zhuanma';
		$force = false;
		//转码完成后通知到你的业务服务器。
		$notifyUrl = 'http://music.liurizhao.zaiyoudao.com/music/port/qiniu.php';
		$config = new \Qiniu\Config();
		#dump($err);die;
		//$config->useHTTPS=true;
		$pfop = new PersistentFop($auth, $config);
		//要进行转码的转码操作。 http://developer.qiniu.com/docs/v6/api/reference/fop/av/avthumb.html
		$name_array = explode(".",$key);
		
		$fops = "avthumb/mp3/ss/0/t/30|saveas/" . \Qiniu\base64_urlSafeEncode($bucket . ":".$name_array[0]."_s.mp3");
		list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notifyUrl, $force);
		
		#暂时不用
		/* echo "\n====> pfop avthumb result: \n";
		if ($err != null) {
			var_dump($err);
		} else {
			echo "PersistentFop Id: $id\n";
		}
		//查询转码的进度和状态
		list($ret, $err) = $pfop->status($id);
		echo "\n====> pfop avthumb status: \n";
		if ($err != null) {
			var_dump($err);
		} else {
			var_dump($ret);
		} */
	}
	
	
	
	public function Set_uid(){
		$_SESSION['u_id'] = I("param.u_id");
		if($_SESSION['u_id'] > 1){
			$info = 1;
		}else{
			$info = 2;
		}
		$this->ajaxReturn($info);
	}
	
	/* 初始化 */
	 public function if_session(){
		 $m_common_user = M('common_user');
		  $map['id'] = $_SESSION['u_id'];
		  $map['group_id'] = 9;
		 $map['status'] = 1;
		 $user_info = $m_common_user->where($map)->find();
		# dump($usser_info);die;
		 if($user_info['id'] <= 1){
			 $this->error("请选择音乐人",U("Admin/User/Manage"));
		 }else{
			$this->assign("user_info",$user_info);
		 }
		 
		 
	 }
	
	
	
	public function type_zhuanma($type,$bit,$result,$url){
			$m_mall_content_music = M("mall_content_music");
			#$type = 4;
			$this->upload_video($url,$type,$bit);
			$music_add['type'] = $type;
			$music_add['form_id'] = $result;
			$name_array = explode(".",$url);
			$music_add['url'] = "http://p7j34hu3o.bkt.clouddn.com/".$name_array[0]."_".$type.".mp3";
			$m_mall_content_music->add($music_add);
		}
		
		public function add_my($type,$result,$url){
			$m_mall_content_music = M("mall_content_music");
			$music_add['type'] = $type;
			$music_add['form_id'] = $result;
			$music_add['url'] = $url;
			$m_mall_content_music->add($music_add);
		}
		
		public function upload_video($key,$i,$bit_rate) {
			$accessKey = "8sc_uncdqBnQUYyWViRALobZH33YO_lZKD65Y04a";
			$secretKey = "FczTgs6OmHBb7jke7pExGeujvxIHXO0trUCIbmBE";
			$bucket = "music";
			$auth = new Auth($accessKey, $secretKey);
			//要转码的文件所在的空间和文件名。
			#$key = '1527143791383.flac';
			//转码是使用的队列名称。 https://portal.qiniu.com/mps/pipeline   1527231255422.flac
			$pipeline = 'music_zhuanma';
			$force = false;
			//转码完成后通知到你的业务服务器。
			$notifyUrl = 'http://music.liurizhao.zaiyoudao.com/music/port/qiniu.php';
			$config = new \Qiniu\Config();
			#dump($err);die;
			//$config->useHTTPS=true;
			$pfop = new PersistentFop($auth, $config);
			//要进行转码的转码操作。 http://developer.qiniu.com/docs/v6/api/reference/fop/av/avthumb.html
			$name_array = explode(".",$key);
			
			$fops = "avthumb/mp3/ab/".$bit_rate."|saveas/" . \Qiniu\base64_urlSafeEncode($bucket . ":".$name_array[0]."_".$i.".mp3");
			list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notifyUrl, $force);
			/* dump($bucket);
			dump($key);
			dump($fops);
			dump($pipeline);
			dump($notifyUrl);
			
			dump($err);
			die; */
			
			#暂时不用
			/* echo "\n====> pfop avthumb result: \n";
			if ($err != null) {
				var_dump($err);
			} else {
				echo "PersistentFop Id: $id\n";
			}
			//查询转码的进度和状态
			list($ret, $err) = $pfop->status($id);
			echo "\n====> pfop avthumb status: \n";
			if ($err != null) {
				var_dump($err);
			} else {
				var_dump($ret);
			} */
		}
	
	 public function upload(){

        Vendor('Qny.autoload');
        // 用于签名的公钥和私钥
        $accessKey = '8sc_uncdqBnQUYyWViRALobZH33YO_lZKD65Y04a';
        $secretKey = 'FczTgs6OmHBb7jke7pExGeujvxIHXO0trUCIbmBE';
        // 初始化签权对象
        $auth = new Auth($accessKey, $secretKey);
        // 空间名  https://developer.qiniu.io/kodo/manual/concepts
//        p78151fwl.bkt.clouddn.com
        $bucket = 'music';
        // 生成上传Token
        $token = $auth->uploadToken($bucket);
        // 构建 UploadManager 对象
        $uploadMgr = new UploadManager();
        // 上传文件到七牛
        $a=$_FILES['userfile'];
        $filePath = $a['tmp_name'];
        $houzhui=trim(strrchr($a['type'], '/'),'/');
        $url = 'http://p7j34hu3o.bkt.clouddn.com/';
        $key = time().rand(000,999).'.'.$houzhui;
		#http://p7j34hu3o.bkt.clouddn.com/1527143791383.flac?avinfo
        list($ret, $err) = $uploadMgr->putFile($token,$key,$filePath);
//        echo "\n====> putFile result: \n";
        if ($err !== null) {//上传出错
            var_dump($err);
        } else {//上传成功
            $true_url=$url.$ret['key'];
            //存入数据库
            //设置编辑器公共上传路径
            $userid = getUID()?getUID():0;
            $m_common_upload = M('common_upload');
            $m_common_upload_type = M('common_upload_type');

            //判断是否有类型没有用就新建

            $cutmap['title'] = $houzhui;
            $cutdata = $m_common_upload_type->where($cutmap)->find();

            if($cutdata){//找到了

                $cuttype = $cutdata['id'];

            }else{//没有

                $cutsdata['title'] = "$houzhui";
                $cutsdata['status'] = 1;
                $cuttype = $m_common_upload_type->add($cutsdata);


            }
            //判断用户
            $uid = $userid;
            //把上传内容存放入数据库
            $cudata =array(
                'status'=>1,
                'url'=> $true_url,
                'title'=>$key,
                'original'=>$a['name'],
                'type'=>$cuttype,
                'size'=>$a['size'],
                'time'=>time(),
                'uid'=>$uid,

            );
            $m_common_upload->add($cudata);

            echo($true_url);

        }
    }

	
	
	
	
	
	
	/**
	 * 页面管理
	 */
    public function Song(){
		$this->if_session();
		//页面配置
		$page = array(
			'title'=>'单曲管理',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//判断是否搜索状态
		$status = I('param.status');
		if($status){
			$map['status'] = $status;
			$this->assign('status',$status);
		}else{
			$map['status'] = array('in','1,2,3,4');
		}
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		$map['type'] = get_mall_model_conf('MALL_SINGLE');
		$map['uid'] = $_SESSION['u_id'];
		
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list = $m_mall_content->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
		}
		#dump($list);die;
		//赋值
		$this->assign('list',$list);
		
		$status_list = getstatus();
		$this->assign('status_list',$status_list);
		$this->display();
	}
	
	
	/**
	 * 新增页面
	 */
	public function Create(){
		$this->if_session();
		//判断是否是ajax请求 
		/* $accessKey = '8sc_uncdqBnQUYyWViRALobZH33YO_lZKD65Y04a';
		$secretKey = 'FczTgs6OmHBb7jke7pExGeujvxIHXO0trUCIbmBE';
		$auth = new Auth($accessKey, $secretKey);
		$bucketName = 'music';
		$token = $auth->uploadToken($bucketName); */
		
		$m_mall_content = M("mall_content");
		$m_cms_style = M("cms_style");
		$m_mall_content_img = M("mall_content_img");
		include_once 'upload.func.php';
		if(IS_POST){
			//获得数据
			$files = $_FILES['color_img']; 
			foreach($files as $i=>$v){
				foreach($files[$i] as $ii=>$vv){
					$files_list[$ii][$i] = $files[$i][$ii];
				}
			}
			$files = $files_list;
			
			foreach($files as $fileInfo) {  
				$res = uploadFile($fileInfo);  
				if(isset($res['dest'])) {  
					$uploadFiles[] = $res['dest'];  
				}  
			} 
			$str = '';
			$uploadFiles=array_filter($uploadFiles);
			
			/* foreach($uploadFiles as $i=>$v){
				$img_name_list = explode("/",$uploadFiles[$i]);
				$count = count($img_name_list);
				$str_str = substr($uploadFiles[$i],1);
				
				if($i == 0){
					$str .= $str_str;
				}else{
					$str .= ','.$str_str;
				}
				
				upload_file_name($img_name_list[$count - 1],$files[$i]['name'],$uploadFiles[$i],$files[$i]['size']);
			} */
			
			
			$data = I();
			$style = $data['style'];
			$data['value'] = I('param.value','','');
			if($style){
				$data['style'] = implode(',',$data['style']);
			}
			$data['uid'] = $_SESSION['u_id'];
			$data['type'] = get_mall_model_conf('MALL_SINGLE');
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			$data['status'] = I('param.status');
			
			$result = $m_mall_content->add($data);
			if($result){
				
				#请求http://p7j34hu3o.bkt.clouddn.com/1527143791383.flac?avinfo   获取 bit_rate(码率)  >320k  无损   320k超品 128k高品  64k 流畅
				$bit_name = $data['mp3']."?avinfo";
				$bit_result = file_get_contents($bit_name);
				$bit_array = json_decode($bit_result,true);
				$bit_rate = $bit_array['format']['bit_rate'];
				
				#判断大小，对应转码
				$music_url = explode(".com/",$data['mp3']);
				$music_urls = $music_url[1];
				
				if($bit_rate < 70000 and $bit_rate > 60000){
					$this->add_my(4,$result,$data['mp3']);
					$this->add_my(3,$result,"");
					$this->add_my(2,$result,"");
					$this->add_my(1,$result,"");
				}else if($bit_rate < 200000 and $bit_rate > 125000){
					$this->type_zhuanma(4,"64k",$result,$music_urls);
					$this->add_my(3,$result,$data['mp3']);
					$this->add_my(2,$result,"");
					$this->add_my(1,$result,"");
				}else if($bit_rate < 340000 and $bit_rate > 300000){
					#修改路径为128k的
					album_save_url($result,$music_urls);
					
					$this->type_zhuanma(4,"64k",$result,$music_urls);
					$this->type_zhuanma(3,"128k",$result,$music_urls);
					$this->add_my(2,$result,$data['mp3']);
					$this->add_my(1,$result,"");
				}else if($bit_rate > 340000){
					#修改路径为128k的
					album_save_url($result,$music_urls);
					
					$this->type_zhuanma(4,"64k",$result,$music_urls);
					$this->type_zhuanma(3,"128k",$result,$music_urls);
					$this->type_zhuanma(2,"320k",$result,$music_urls);
					$this->add_my(1,$result,$data['mp3']);
				}
				
				
				
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					
					upload_file_name($img_name_list[$count - 1],$files[$i]['name'],$uploadFiles[$i],$files[$i]['size']);
					mall_img(1,$result,trim($uploadFiles[$i],'.'));
				}
			}
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
				#创建单曲与风格的关联  zyd_cms_style  
				add_style(1,$result,$style); 
				
				$this->success('新增成功', U('Mall/User/Create'));
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置
				$this->error('新增失败');
			}	
		}else{
			#查询语言
			$langue_list = getlangeues();
			#查询流派风格
			$style_list = gettypes();
			/* $this->assign("token",$token); */
			$this->assign("langue_list",$langue_list);
			$this->assign("style_list",$style_list);
			$this->display();
		}
		
	
	}
	
	
	/**
	 * 批量改变页面状态
	 */
	public function Delete($id,$status=0){
		$this->if_session();
		//判断是否是ajax请求
		if(IS_AJAX){
			$m_mall_content = M('mall_content');
			
			$id = $id?$id:I('param.id');
			$status = $status?$status:I('param.status');
			
			if($id){
				$id = explode(',',$id);
				foreach($id as $i=>$k){
					$map['id'] = $id[$i];
					$data['status'] = $status;
					$m_mall_content->where($map)->save($data);
				}
				//返回信息
				$info = get_errcode(0);
			}else{
				$info = get_errcode(10000001);
			}
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
	}
	
	
	
	/**
	 * 编辑歌曲
	 */
	public function Edit_song(){
		$this->if_session();
		$m_mall_content = M('mall_content');
		$m_mall_content_music = M('mall_content_music');
		$map['id'] = I('param.id');
		//判断是否是ajax请求
		if(IS_POST){
			//获得数据
			$data = I('');
			unset($data['id']);
			$style = I('param.style');
			$data['style'] = implode(',',I('param.style'));
			$data['value'] = I('param.value','','');
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			$result = $m_mall_content->where($map)->save($data);
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']  
				$find_map['form_id'] = $map['id'];
				$find_map['url'] = $data['mp3'];
				$find_data = $m_mall_content_music->where($find_map)->find();
				
				if(!$find_data){
					
					#不相等的时候进行编码以及修改
					$result = $map['id'];
					#删除修改前转码的歌曲信息
					$delete_map['form_id'] = $result;
					$m_mall_content_music->where($delete_map)->delete();
					
					#请求http://p7j34hu3o.bkt.clouddn.com/1527143791383.flac?avinfo   获取 bit_rate(码率)  >320k  无损   320k超品 128k高品  64k 流畅
					$bit_name = $data['mp3']."?avinfo";
					$bit_result = file_get_contents($bit_name);
					$bit_array = json_decode($bit_result,true);
					$bit_rate = $bit_array['format']['bit_rate'];
					
					#判断大小，对应转码
					$music_url = explode(".com/",$data['mp3']);
					$music_urls = $music_url[1];
					
					if($bit_rate < 70000 and $bit_rate > 60000){
						$this->add_my(4,$result,$data['mp3']);
						$this->add_my(3,$result,"");
						$this->add_my(2,$result,"");
						$this->add_my(1,$result,"");
					}else if($bit_rate < 200000 and $bit_rate > 125000){
						$this->type_zhuanma(4,"64k",$result,$music_urls);
						$this->add_my(3,$result,$data['mp3']);
						$this->add_my(2,$result,"");
						$this->add_my(1,$result,"");
					}else if($bit_rate < 340000 and $bit_rate > 300000){
						#修改路径为128k的
						album_save_url($result,$music_urls);
						
						$this->type_zhuanma(4,"64k",$result,$music_urls);
						$this->type_zhuanma(3,"128k",$result,$music_urls);
						$this->add_my(2,$result,$data['mp3']);
						$this->add_my(1,$result,"");
					}else if($bit_rate > 340000){
						#修改路径为128k的
						album_save_url($result,$music_urls);
						
						$this->type_zhuanma(4,"64k",$result,$music_urls);
						$this->type_zhuanma(3,"128k",$result,$music_urls);
						$this->type_zhuanma(2,"320k",$result,$music_urls);
						$this->add_my(1,$result,$data['mp3']);
					}
				}
				
				
				#创建单曲与风格的关联  zyd_cms_style  
				add_style(1,$map['id'],$style); 
				$this->success('编辑成功', U('Mall/User/Song'));
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置
				$this->error('编辑失败');
			}
		}else{
			#查询语言
			$langue_list = getlangeues();
			#查询流派风格
			$style_list = gettypes();
			#详情
			$map['type'] = get_mall_model_conf('MALL_SINGLE');
			$map['status'] = array("in",'2,4');
			$map['uid'] = $_SESSION['u_id'];
			$data = $m_mall_content->where($map)->find();
			$style_list = if_style($style_list,$data['style']);
			
			$this->assign('langue_list',$langue_list);
			$this->assign('style_list',$style_list);
			$this->assign('data',$data);
			$this->display();
		}
	}
	
	/* 新增活动 */
	public function create_activity(){
		$this->if_session();
		
		include_once 'upload.func.php';
		$m_mall_content = M("mall_content");
		$m_mall_content_money = M("mall_content_money");
		if(IS_POST){
			$value = I('param.value','','');
		
			 $pattern_img = '/<img (.+?)\/>/';
			 preg_match_all($pattern_img,$value,$matches_img);
			 
			 $pattern_src = '/src="(.+?)"/';
			foreach($matches_img[1] as $ii=>$vv){
				preg_match_all($pattern_src,$vv,$matches_src);
				$img_url = if_url($matches_src[1][0]);
				if($img_url){
					$matches_src_list_jiequ[] = cut_image($img_url);
					$matches_src_list[] = $img_url;
				}
				
			}
			$matches_src_str = implode(",",$matches_src_list);
			
			//获得数据
			$data = I();
			$data['url'] = $matches_src_str;
			$style = I('param.style');
			$data['style'] = implode(',',I('param.style'));
			$data['value'] = I('param.value','','');
			$data['uid'] = $_SESSION['u_id'];
			$data['type'] = get_mall_model_conf('MALL_ACTIVITY');
			$data['time'] = time();
			$data['release_time'] = strtotime(I("param.release_time"));
			$data['ip'] = get_client_ip();
			$data['status'] = 2;
			$result = $m_mall_content->add($data);
			
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']
				#添加相册
				foreach($matches_src_list as $i=>$v){
					mall_img(5,$result,trim($matches_src_list[$i],'.'));
				}
				#创建单曲与风格的关联  zyd_cms_style  
				add_style(3,$result,$style); 
				#创建价格
				$begin_array = I('param.huodong_begin');
				$end_array = I('param.huodong_end');
				$money_array = I('param.huodong_money');
				$name_array = I('param.huodong_name');
				$number = I('param.number');
				foreach($begin_array as $i=>$v){
					$add_begin['begin_time'] = strtotime($begin_array[$i]);
					$add_begin['end_time'] = strtotime($end_array[$i]);
					$add_begin['goods_money'] = $money_array[$i];
					$add_begin['number'] = $number[$i];
					$add_begin['name'] = $name_array[$i];
					$add_begin['goods_id'] = $result;	
					$m_mall_content_money->add($add_begin);
				}
				
				$this->success('新增成功', U('Mall/User/activity'));
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置
				$this->error('新增失败');
			}	
		}else{
			
			#查询流派风格
			$style_list = gettypes();
			
			/* $this->assign("token",$token); */
			$this->assign("style_list",$style_list);
			$this->display();
		}
	}
	
	/**
	 *活动列表 
	 */
    public function Activity(){
		$this->if_session();
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		//页面配置
		$page = array(
			'title'=>'活动列表',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//判断是否搜索状态
		$status = I('param.status');
		if($status){
			$map['status'] = $status;
			$this->assign('status',$status);
		}else{
			$map['status'] = array('in','1,2,3,4');
		}
		
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$map['type'] = get_mall_model_conf('MALL_ACTIVITY');
		$map['uid'] = $_SESSION['u_id'];
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		
		$list = $m_mall_content ->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content ->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$style_name = array();
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
			
			$list[$i]['style_name'] = style_str($list[$i]['style']);
		
		}
		
		//dump($list);die;
		//赋值
		$this->assign('list',$list);
		$status_list = getstatus();
		$this->assign('status_list',$status_list);
		$this->display();
	}
	
	/**
	 * 歌单列表（音乐人）
	 */
    public function playlist(){
		$this->if_session();
		$m_mall_content = M('mall_content');
		
		//获得菜单信息
		$map['type'] = get_mall_model_conf('MALL_PLAYLIST');
		$map['uid'] = $_SESSION['u_id'];
		$map['status'] = 1;
		$list = $m_mall_content->where($map)->order('sort desc')->select();
		
		//赋值
		$this->assign('list',$list);
		$this->display();
	}
	
		/**
	 * 编辑菜单
	 */
	public function Edit_playlist(){
    
		$this->if_session();
		//判断是否是ajax请求
		if(IS_AJAX){

			$m_mall_content = M('mall_content');
			$map['id'] = I('param.id');
			$map['uid'] = $_SESSION['u_id'];
			$data = I('');
			unset($data['id']);
		
			$result = $m_mall_content->where($map)->save($data);
			
			//返回信息
			$info = $result?get_errcode(0):get_errcode(-1);
		
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
	}
	
	/**
	 * 批量删除菜单
	 */
	public function Delete_playlist($id,$status=0){
		$this->if_session();
	
		//判断是否是ajax请求
		if(IS_AJAX){
				
			$m_mall_content = M('mall_content');
		
			$id = $id?$id:I('param.id');
			$status = $status?$status:I('param.status');
			
			if($id){
				$id = explode(',',$id);
				foreach($id as $i=>$k){
					$map['id'] = $id[$i];
					$data['status'] = $status;
					$m_mall_content->where($map)->save($data);
					
				}
				
				//返回信息
				$info = get_errcode(0);
			
			}else{
				
				$info = get_errcode(10000001);
			}
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);
		$this->ajaxReturn($info);
	}
	
	/**
	 * 页面管理
	 */
    public function set_playlist(){
		$this->if_session();
		//页面配置
		$page = array(
			'title'=>'单曲管理',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		$map['type'] = get_mall_model_conf('MALL_SINGLE');
		$map['uid'] = $_SESSION['u_id'];
		$map['status'] = 1;
		
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list = $m_mall_content->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
		}
		//赋值
		$this->assign('list',$list);
		
		$status_list = getstatus();
		$this->assign('status_list',$status_list);
		
		#歌单列表
		$playlist_map['type'] = get_mall_model_conf('MALL_PLAYLIST');
		$playlist_map['uid'] = $_SESSION['u_id'];
		$playlist_map['status'] = 1;
		$playlist_list = $m_mall_content->where($playlist_map)->select();
		$this->assign('playlist_list',$playlist_list);
		$this->display();
	}
	
	
	/* 新增专辑 */
	 public function create_album(){
		 $this->if_session();
		 
		include_once 'upload.func.php';
		$m_mall_content = M("mall_content");
		 if(IS_POST){
			$style = I("param.style");
			$style_array = implode(',',$style);             //流派风格 
			$data['langue'] = I("param.langue");         //语言
			if($style_array){
				$data['style'] = $style_array;
			}
			$data['isrc'] = I("param.isrc");           //歌手
			$data['singer'] = I("param.singer");           //歌手
			$data['banner_img'] = I("param.banner_img");           //歌手
			$data['name'] = I("param.name");               //专辑名称
			$data['money'] = I("param.money");       //出售单价
			$data['inventory'] = I("param.inventory");       //发行量
			$data['release_time'] = strtotime(I("param.release_time"));       //发行时间  
			$data['img'] = I("param.img");       //封面图
			$data['bottom_img'] = I("param.bottom_img");       //封底图
			$data['intro'] = I("param.intro");       //专辑介绍
			$data['time'] = time();
			$data['type'] = get_mall_model_conf('MALL_ALBUM');
			$data['ip'] = get_client_ip();
			$data['status'] = 2;
			$data['value'] = I('param.value')?I('param.value'):'';
			$data['uid'] = $_SESSION['u_id'];
			$result = $m_mall_content->add($data);
			#添加歌曲
			if($result){
				#添加流派风格
				add_style(2,$result,$style); 
				#获取对应歌曲个数
				$music_img_count = I('param.music_img_count');
				$xuanchuan_img_count = I('param.xuanchuan_img_count');
				$mp3_list = I('param.mp3');    #歌曲文件
				$music_name = I("param.music_name");   #歌曲名称 
				$langues = I('param.langues');    #语言
				$producers = I("param.producers");    #出品方 
				$producer = I("param.producer");    #制作人 
				$singers = I("param.singers");    #演唱者 
				$mixings = I("param.mixings");    #混音 
				$records = I("param.records");    #录音 
				$composes = I("param.composes");    #作曲 
				$lyrics = I("param.lyrics");    #作曲
				
				# 内页 color_img
				$color_img = $_FILES['color_img'];
				foreach($color_img as $i=>$v){
					foreach($color_img[$i] as $ii=>$vv){
						$color_img_list[$ii][$i] = $color_img[$i][$ii];
					}
				}
				foreach($color_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					
					if(isset($res['dest'])) {  
						$uploadFiless[] = $res['dest'];  
					}  
				}
				$uploadFiless=array_filter($uploadFiless);
				foreach($uploadFiless as $i=>$v){
					$img_name_list = explode("/",$uploadFiless[$i]);
					$count = count($img_name_list);
					$str_strs = substr($uploadFiless[$i],1);
					$neiye_array[] = $str_strs;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$color_img_list[$i]['name'],$uploadFiless[$i],$color_img_list[$i]['size']);
					mall_img(4,$result,trim($uploadFiless[$i],'.'));
				}
				
				#歌词 music_lyrics
				$music_lyrics = $_FILES['music_lyrics'];
				foreach($music_lyrics as $i=>$v){
					foreach($music_lyrics[$i] as $ii=>$vv){
						$music_lyrics_list[$ii][$i] = $music_lyrics[$i][$ii];
					}
				}
			
				#歌词本底衬页图  foil_img
				$foil_img = $_FILES['foil_img'];
				
				foreach($foil_img as $i=>$v){
					foreach($foil_img[$i] as $ii=>$vv){
						$foil_img_list[$ii][$i] = $foil_img[$i][$ii];
					}
				}
				
				$uploadFiles = array();
				
				#歌词上传
				foreach($music_lyrics_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					
					if(isset($res['dest'])) {  
						$uploadFiles[] = $res['dest'];  
					}  
				}
				$uploadFiles=array_filter($uploadFiles);
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					$geci_array[] = $str_str;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$music_lyrics_list[$i]['name'],$uploadFiles[$i],$music_lyrics_list[$i]['size']);
				}
				
				#歌词本底衬页图  foil_img
				$uploadFiles = array();
				foreach($foil_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					if(isset($res['dest'])) {  
						$uploadFiles[] = $res['dest'];  
					}  
				}
				$uploadFiles=array_filter($uploadFiles);
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					$gecichenye_array[] = $str_str;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$foil_img_list[$i]['name'],$uploadFiles[$i],$foil_img_list[$i]['size']);
				}
				
				#宣传图  xuanchuan_img
				$xuanchuan_img = $_FILES['xuanchuan_img'];
				foreach($xuanchuan_img as $i=>$v){
					foreach($xuanchuan_img[$i] as $ii=>$vv){
						$xuanchuan_img_list[$ii][$i] = $xuanchuan_img[$i][$ii];
					}
				}
				
				$uploadFiless = array();
				foreach($xuanchuan_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					if(isset($res['dest'])) {  
						$uploadFiless[] = $res['dest'];  
					}  
				}
				$uploadFiless=array_filter($uploadFiless);
				foreach($uploadFiless as $i=>$v){
					$img_sname_list = explode("/",$uploadFiless[$i]);
					$count = count($img_sname_list);
					$str_strs = substr($uploadFiless[$i],1);
					$gecichenye_array[] = $str_strs;
					#源文件与现文件记录
					upload_file_name($img_sname_list[$count - 1],$xuanchuan_img_list[$i]['name'],$uploadFiless[$i],$xuanchuan_img_list[$i]['size']);
				}
				#添加该专辑下的歌曲
				$cc_count = 0;
				$cc_counts = 0;
				
				foreach($mp3_list as $gi=>$gv){
					$song_map['mp3'] = $mp3_list[$gi];
					$song_map['name'] = $music_name[$gi];
					$song_map['langue'] = $langues[$gi];
					$song_map['producers'] = $producers[$gi];
					$song_map['producer'] = $producer[$gi];
					$song_map['singer'] = $singers[$gi];
					$song_map['mixing'] = $mixings[$gi];
					$song_map['record'] = $records[$gi];
					$song_map['compose'] = $composes[$gi];
					$song_map['lyrics'] = $lyrics[$gi];
					
					if($geci_array[$gi]){
						$song_map['value'] = $geci_array[$gi];
					}
					$song_map['form_id'] = $result;
					$song_map['uid'] = $_SESSION['u_id'];
					$song_map['type'] = get_mall_model_conf('MALL_SONG');  //表示专辑下的歌曲
					$song_map['ip'] = get_client_ip();
					$song_map['status'] = 1;
					$geci_result = $m_mall_content->add($song_map);
					
					#添加试听歌曲
					$shiting_array = explode(".com/",$mp3_list[$gi]);
					$this->type_zhuanma_shiting(5,$geci_result,$shiting_array[1]);
					
					for ($x=0; $x<$music_img_count[$gi]; $x++) {
						mall_img(2,$geci_result,trim($uploadFiles[$cc_count],'.'));
						$cc_count ++;
					}
					
					for ($x=0; $x<$music_img_count[$gi]; $x++) {
						mall_img(3,$geci_result,trim($uploadFiless[$cc_counts],'.'));
						$cc_counts ++;
					}
						
				}
			}
			
			
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
				$this->success('新增成功', U('Mall/User/Album'));
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置   
				$this->error('新增失败');
			}
		 }else{
			 #查询语言
			$langeue_list = getlangeues();
			#查询流派风格
			$type_list = gettypes();
			foreach($type_list as $i=>$v){
				$type_str .= "<option value ='".$type_list[$i]['id']."'>".$type_list[$i]['name']."</option>";
			}
			foreach($langeue_list as $i=>$v){
				$langeue_str .= "<option value ='".$langeue_list[$i]['id']."'>".$langeue_list[$i]['name']."</option>";
			}
			#dump($langeue_str);die; 
			$this->assign("type_str",$type_str);
			$this->assign("langeue_str",$langeue_str);
			$this->assign("langeue_list",$langeue_list);
			$this->assign("type_list",$type_list);
			$this->assign("time",time());
			$this->display();			
		 }
		 
					
		 }
	 
	
	/**
	 *  专辑管理
	 */
    public function  Album(){
		$this->if_session();
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//判断是否搜索状态
		$status = I('param.status');
		if($status){
			$map['status'] = $status;
			$this->assign('status',$status);
		}else{
			$map['status'] = array('in','1,2,3,4');
		}
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		$map['type'] = get_mall_model_conf('MALL_ALBUM');
		$map['uid'] = $_SESSION['u_id'];
		$list = $m_mall_content->where($map)->order('time desc')->page($_GET['p'].',50')->select();
		#dump($map);die;
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出 
		$this->assign('pages',$show);
		
		$status_list = getstatus();
		//dump($status_list);die;
		//赋值
		$this->assign('list',$list);
		$this->assign('status_list',$status_list);
		$this->display();
	}
	
	
	
	/* 编辑专辑 */
	 public function Edit_album(){
		 $this->if_session();
		$m_mall_content = M('mall_content');
		$m_common_upload = M('common_upload');
		include_once 'upload.func.php';
		
		//判断是否是ajax请求
		if(IS_POST){
			
			# 编辑专辑相应内容
			$style = I("param.style");
			$style_array = implode(',',$style);             //流派风格
			$data['langue'] = I("param.langue");         //语言
			if($style_array){
				$data['style'] = $style_array;
			}
			$data['isrc'] = I("param.isrc");           //歌手
			$data['banner_img'] = I("param.banner_img");           //歌手
			$data['singer'] = I("param.singer");           //歌手
			$data['name'] = I("param.name");               //专辑名称
			$data['money'] = I("param.money");       //出售单价
			$data['inventory'] = I("param.inventory");       //发行量
			$data['release_time'] = strtotime(I("param.release_time"));       //发行时间
			$data['img'] = I("param.img");       //封面图
			$data['bottom_img'] = I("param.bottom_img");       //封底图
			$data['intro'] = I("param.intro");       //专辑介绍
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			$edit_id_map['id'] = I('param.form_id');
			$edit_id_map['uid'] = $_SESSION['u_id'];
			$result = $m_mall_content->where($edit_id_map)->save($data);
				#编辑专辑下歌曲
				$edit_id = I('param.edit_id');    #歌曲id
				$edit_name = I('param.edit_name');    #歌曲名称
				$edit_langues = I('param.edit_langues');    #歌曲语言
				$edit_lyrics = I('param.edit_lyrics');    #作词
				$edit_composes = I('param.edit_composes');    #作曲
				$edit_records = I('param.edit_records');    #录音
				$edit_mixings = I('param.edit_mixings');    #混音
				$edit_singers = I('param.edit_singers');    #演唱者
				$edit_producer = I('param.edit_producer');    #制作人
				$edit_producers = I('param.edit_producers');    #出品方
				$edit_music_lyrics = I('param.edit_music_lyrics');    #歌词
				
				
				foreach($edit_id as $i=>$v){
					$edit_song_map['id'] = $edit_id[$i];
					$edit_song_data['name'] = $edit_name[$i];
					$edit_song_data['langue'] = $edit_langues[$i];
					$edit_song_data['lyrics'] = $edit_lyrics[$i];
					$edit_song_data['compose'] = $edit_composes[$i];
					$edit_song_data['record'] = $edit_records[$i];
					$edit_song_data['mixing'] = $edit_records[$i];
					$edit_song_data['singer'] = $edit_singers[$i];
					$edit_song_data['producer'] = $edit_producer[$i];
					$edit_song_data['producers'] = $edit_producers[$i];
					$edit_song_data['value'] = $edit_music_lyrics[$i];
					#歌词  file上传
					$m_mall_content->where($edit_song_map)->save($edit_song_data);
				}
				
				
				
				#新增专辑下歌曲
				
				#添加流派风格
				add_style(2,$edit_id_map['id'],$style); 
				#获取对应歌曲个数
				$music_img_count = I('param.music_img_count');
				$xuanchuan_img_count = I('param.xuanchuan_img_count');
				$mp3_list = I('param.mp3');    #歌曲文件
				$music_name = I("param.music_name");   #歌曲名称 
				$langues = I('param.langues');    #语言
				$producers = I("param.producers");    #出品方 
				$producer = I("param.producer");    #制作人 
				$singers = I("param.singers");    #演唱者 
				$mixings = I("param.mixings");    #混音 
				$records = I("param.records");    #录音 
				$composes = I("param.composes");    #作曲 
				$lyrics = I("param.lyrics");    #作曲
				
				#歌词 music_lyrics
				$music_lyrics = $_FILES['music_lyrics'];
				foreach($music_lyrics as $i=>$v){
					foreach($music_lyrics[$i] as $ii=>$vv){
						$music_lyrics_list[$ii][$i] = $music_lyrics[$i][$ii];
					}
				}
			
				#歌词本底衬页图  foil_img
				$foil_img = $_FILES['foil_img'];
				
				foreach($foil_img as $i=>$v){
					foreach($foil_img[$i] as $ii=>$vv){
						$foil_img_list[$ii][$i] = $foil_img[$i][$ii];
					}
				}
				
				$uploadFiles = array();
				
				#歌词上传
				foreach($music_lyrics_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					
					if(isset($res['dest'])) {  
						$uploadFiles[] = $res['dest'];  
					}  
				}
				$uploadFiles=array_filter($uploadFiles);
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					$geci_array[] = $str_str;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$music_lyrics_list[$i]['name'],$uploadFiles[$i],$music_lyrics_list[$i]['size']);
				}
				
				#歌词本底衬页图  foil_img
				$uploadFiles = array();
				foreach($foil_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					if(isset($res['dest'])) {  
						$uploadFiles[] = $res['dest'];  
					}  
				}
				$uploadFiles=array_filter($uploadFiles);
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					$gecichenye_array[] = $str_str;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$foil_img_list[$i]['name'],$uploadFiles[$i],$foil_img_list[$i]['size']);
				}
				
				#宣传图  xuanchuan_img
				$xuanchuan_img = $_FILES['xuanchuan_img'];
				foreach($xuanchuan_img as $i=>$v){
					foreach($xuanchuan_img[$i] as $ii=>$vv){
						$xuanchuan_img_list[$ii][$i] = $xuanchuan_img[$i][$ii];
					}
				}
				
				$uploadFiless = array();
				foreach($xuanchuan_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					if(isset($res['dest'])) {  
						$uploadFiless[] = $res['dest'];  
					}  
				}
				$uploadFiless=array_filter($uploadFiless);
				foreach($uploadFiless as $i=>$v){
					$img_sname_list = explode("/",$uploadFiless[$i]);
					$count = count($img_sname_list);
					$str_strs = substr($uploadFiless[$i],1);
					$gecichenye_array[] = $str_strs;
					#源文件与现文件记录
					upload_file_name($img_sname_list[$count - 1],$xuanchuan_img_list[$i]['name'],$uploadFiless[$i],$xuanchuan_img_list[$i]['size']);
				}
				#添加该专辑下的歌曲
				$cc_count = 0;
				$cc_counts = 0;
				
				foreach($mp3_list as $gi=>$gv){
					$song_map['mp3'] = $mp3_list[$gi];
					$song_map['name'] = $music_name[$gi];
					$song_map['langue'] = $langues[$gi];
					$song_map['producers'] = $producers[$gi];
					$song_map['producer'] = $producer[$gi];
					$song_map['singer'] = $singers[$gi];
					$song_map['mixing'] = $mixings[$gi];
					$song_map['record'] = $records[$gi];
					$song_map['compose'] = $composes[$gi];
					$song_map['lyrics'] = $lyrics[$gi];
					
					if($geci_array[$gi]){
						$song_map['value'] = $geci_array[$gi];
					}
					$song_map['form_id'] = $edit_id_map['id'];
					#$song_map['uid'] = $_SESSION['u_id'];
					$song_map['type'] = get_mall_model_conf('MALL_SONG');  //表示专辑下的歌曲
					$song_map['ip'] = get_client_ip();
					$song_map['status'] = 1;
					$geci_result = $m_mall_content->add($song_map);
					
					#添加试听歌曲
					$shiting_array = explode(".com/",$mp3_list[$gi]);
					$this->type_zhuanma_shiting(5,$geci_result,$shiting_array[1]);
					
					for ($x=0; $x<$music_img_count[$gi]; $x++) {
						mall_img(2,$geci_result,trim($uploadFiles[$cc_count],'.'));
						$cc_count ++;
					}
					
					for ($x=0; $x<$music_img_count[$gi]; $x++) {
						mall_img(3,$geci_result,trim($uploadFiless[$cc_counts],'.'));
						$cc_counts ++;
					}
						
				}
			
			
			if($cc_count >0 or $result>0){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
			
				$this->success('编辑成功', U('Mall/User/Album'));
			
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置  
			
				$this->error('编辑失败');
			
			}
		
		}else{
			 #查询语言
			$langeue_list = getlangeues();
			#查询流派风格
			$style_list = gettypes();
			
			$map['id'] = I('param.id');
			$map['type'] = get_mall_model_conf('MALL_ALBUM');
			$map['status'] = array('neq','0');
			$map['uid'] = $_SESSION['u_id'];
			$data = $m_mall_content->where($map)->find();
			
			#查询专辑下歌曲
			$f_map['form_id'] = $data['id'];
			$f_map['type'] = 17;    //专辑下歌曲
			$f_map['status'] = 1;  
			$f_list = $m_mall_content->where($f_map)->select();
			#查看歌曲名称
			foreach($f_list as $i=>$v){
				$url = $f_list[$i]['mp3'];
				$url_map['url'] = array("like","%$url%");
				$url_map['status'] = 1;
				$url_data = $m_common_upload->where($url_map)->find();
				$f_list[$i]['song_name'] = $url_data['original'];
				$f_list[$i]['song_size'] = getFilesize($url_data['size']);
				
				$value = $f_list[$i]['value'];
				$url_map['url'] = array("like","%$value%");
				$url_map['status'] = 1;
				$url_data = $m_common_upload->where($url_map)->find();
				$f_list[$i]['value_name'] = $url_data['original'];
				
				foreach($langeue_list as $ii=>$vv){
					if($langeue_list[$ii]['id'] == $f_list[$i]['langue']){
						$langeue_str[$i] .=  "<option selected='selected' value ='".$langeue_list[$ii]['id']."'>".$langeue_list[$ii]['name']."</option>";
					}else{
						$langeue_str[$i] .=  "<option value ='".$langeue_list[$ii]['id']."'>".$langeue_list[$ii]['name']."</option>";
					}
				}
				
				
				
				
			}
			foreach($langeue_list as $i=>$v){
					$langeue_strs .= "<option value ='".$langeue_list[$i]['id']."'>".$langeue_list[$i]['name']."</option>";
				}
			#dump($langeue_str);die;
			$style_list = if_style($style_list,$data['style']);
			$this->assign("langeue_list",$langeue_list);
			$this->assign("langeue_str",$langeue_str);
			$this->assign("langeue_strs",$langeue_strs);
			$this->assign('data',$data);
			$this->assign('f_list',$f_list);
			$this->assign('style_list',$style_list);
			$this->display();
		}
		 
		 
	 }
	
	
	/**
	 * 页面管理
	 */
    public function playlist_details(){
		$this->if_session();
		//页面配置
		$page = array(
			'title'=>'歌单详情',
			'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
			'author'=>'YiPHP',
			'robots' => 'all',
		);
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		$details_map['id'] = I("param.id");
		$details_map['status'] = 1;
		$details_map['type'] = 20;
		$details_data = $m_mall_content->where($details_map)->find();
		
		$map['type'] = get_mall_model_conf('MALL_SINGLE');
		$map['status'] = 1;
		$map['uid'] = $_SESSION['u_id'];
		$map['id'] = array("in",$details_data['value']);
		
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list = $m_mall_content->where($map)->order('sort desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['img'] = $udata['img'];
		}
		//赋值
		$this->assign('list',$list);
		
		$status_list = getstatus();
		$this->assign('status_list',$status_list);
		
		#歌单id
		$this->assign("details_data",$details_data);
		
		$this->display();
	}
	
	/**
	 * 新增菜单
	 */
	public function Create_playlist(){
		$this->if_session();
		//判断是否是ajax请求
		if(IS_AJAX){

			$m_mall_content = M('mall_content');
			//获得数据
			$data = I();
			
			$data['uid'] = $_SESSION['u_id'];
			$data['type'] = get_mall_model_conf('MALL_PLAYLIST');
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			$data['status'] = 1;
			
			$result = $m_mall_content->add($data);
			//返回信息
			$info = $result?get_errcode(0):get_errcode(-1);
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
	}
	
	/**
	 * 专辑订单
	 */
    public function Music_order(){
		$this->if_session();
		$m_mall_order = M("mall_order");
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		
		//搜索指定用户的订单
		$uid = I('param.uid');
		if($uid){
			$order_map['uid'] = $uid;
		}
		$this->assign('uid',$uid);
		
		//模糊搜索订单号
		$order_id = I('param.order_id');
		if($order_id){
			$order_map['order_id'] = array('like',"%$order_id%");
		}
		$this->assign('order_id',$order_id);
		
		//上传开始结束时间
		$down_money = I('param.down_money');
		$top_money = I('param.top_money');
		if($down_money != null and $top_money != null){
			$order_map['money']  = array(array('egt',$down_money),array('elt',$top_money),'and');
			$this->assign('down_money',$down_money);
			$this->assign('top_money',$top_money);
		}
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$order_map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
		}else{
			$begin_time=time()-2592000;
			$end_time=time()+86400;
		}
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		$map['uid'] = $_SESSION['u_id'];
		$map['status'] = 1;
		$map['type'] = array("in",'22,16,19');
		$list = $m_mall_content->where($map)->field("id")->select();
		
		$list = array_column($list,'id');
		$list = array_unique($list);
		$list_str = implode(',',$list);
		
		$order_map['goods_id'] = array("in",$list_str);
		$order_map['status'] = 1;
		$_GET['p'] = $_GET['p']?$_GET['p']:1;
		$order_list = $m_mall_order->where($order_map)->order("time desc")->page($_GET['p'],20)->select();
		$count      = $m_mall_order->where($order_map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		
		foreach($order_list as $i=>$v){
			$user_map['id'] = $order_list[$i]['uid'];
			$user_data = $m_common_user->where($user_map)->find();
			$order_list[$i]['n_img'] = $user_data['img'];
			#专辑
			$goods_map['id'] = $order_list[$i]['goods_id'];
			$goods_name = $m_mall_content->where($goods_map)->find();
			
			$order_list[$i]['goods_name'] = $goods_name['name'];
			
		}
		$this->assign('pages',$show);
		$this->assign('list',$order_list);
		$this->display();
	}
	
	
	#管理员导出账单
	public function daochu(){
		$this->if_session();
		$m_mall_order = M("mall_order");
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		
		//搜索指定用户的订单
		$uid = I('param.uid');
		if($uid){
			$order_map['uid'] = $uid;
		}
		$this->assign('uid',$uid);
		
		//模糊搜索订单号
		$order_id = I('param.order_id');
		if($order_id){
			$order_map['order_id'] = array('like',"%$order_id%");
		}
		$this->assign('order_id',$order_id);
		
		//上传开始结束时间
		$down_money = I('param.down_money');
		$top_money = I('param.top_money');
		if($down_money != null and $top_money != null){
			$order_map['money']  = array(array('egt',$down_money),array('elt',$top_money),'and');
			$this->assign('down_money',$down_money);
			$this->assign('top_money',$top_money);
		}
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$order_map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
		}else{
			$begin_time=time()-2592000;
			$end_time=time()+86400;
		}
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		$map['uid'] = $_SESSION['u_id'];
		$map['status'] = 1;
		$map['type'] = array("in",'22,16,19');
		$list = $m_mall_content->where($map)->field("id")->select();
		
		$list = array_column($list,'id');
		$list = array_unique($list);
		$list_str = implode(',',$list);
		
		$order_map['goods_id'] = array("in",$list_str);
		$order_map['status'] = 1;
		$_GET['p'] = $_GET['p']?$_GET['p']:1;
		$order_list = $m_mall_order->where($order_map)->order("time desc")->select();
		
		foreach($order_list as $i=>$v){
			$user_map['id'] = $order_list[$i]['uid'];
			$user_data = $m_common_user->where($user_map)->find();
			$order_list[$i]['n_img'] = $user_data['img'];
			$money_list[$i]['nickname'] = $user_data['nickname'];
			#专辑
			$goods_map['id'] = $order_list[$i]['goods_id'];
			$goods_name = $m_mall_content->where($goods_map)->find();
			
			$order_list[$i]['order_id'] = $order_list[$i]['order_id'].' ';
			$order_list[$i]['goods_name'] = $goods_name['name'];
			$order_list[$i]['time'] = date("Y-m-d H:i",$order_list[$i]['time']);
			$order_list[$i]['nickname'] = $user_data['nickname']."-".$user_data['id'];
			
			if($order_list[$i]['pay_type'] == 1){
				$order_list[$i]['zhifu'] = '支付宝';
			}else if($order_list[$i]['pay_type'] == 2){
				$order_list[$i]['zhifu'] = '微信';
			}else if($order_list[$i]['pay_type'] == 3){
				$order_list[$i]['zhifu'] = '余额';
			}
			
		}
		
		$xlsName  = "订单记录";
       $xlsCell  = array(
            array('time','下单时间'),
            array('order_id','订单号'),
            array('nickname','昵称-uid'),
            array('goods_name','来源'),
            array('money','金额'),
            array('money','支付方式'),
        );
		$this->exportExcel($xlsName,$xlsCell,$order_list);
      }
	
	public function exportExcel($expTitle,$expCellName,$manual_export){
		$this->if_session();
		$m_common_user = M("common_user");
		$d_map['id'] = $_SESSION['u_id'];
		$d_map['status'] = 1;
		$user_data =  $m_common_user->where($d_map)->find();
        $xlsTitle = iconv('utf-8', 'gb2312', $expTitle);//文件名称
        $fileName = $user_data['nickname'].date("YmdHi",time());//or $xlsTitle 文件名称可根据自己情况设定
        #$fileName = "123";//or $xlsTitle 文件名称可根据自己情况设定
        $cellNum = count($expCellName);
        $dataNum = count($manual_export);
        import("Org.Util.PHPExcel");
        $objPHPExcel = new \PHPExcel();
		
		$objPHPExcel->getActiveSheet()->getDefaultColumnDimension(A)->setWidth(25);
		$objPHPExcel->getActiveSheet()->getStyle('c')->getAlignment()->setWrapText(true);
		$objPHPExcel->getActiveSheet()->getStyle('d')->getAlignment()->setWrapText(true);
		$objPHPExcel->getActiveSheet()->getStyle('e')->getAlignment()->setWrapText(true);
        $cellName = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ','BA','BB','BC','BD','BE','BF','BG','BH','BI','BJ','BK','BL','BM','BN','BO','BP','BQ','BR','BS','BT','BU','BV','BW','BX','BY','BZ','CA','CB','CC','CD','CE','CF','CG','CH','CI','CJ','CK','CL','CM','CN');
		
        //$objPHPExcel->getActiveSheet(0)->mergeCells('A1:'.$cellName[$cellNum-1].'1');//合并单元格 
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1');  
        for($i=0;$i<$cellNum;$i++){
            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i].'1', $expCellName[$i][1]); 
        } 
          // Miscellaneous glyphs, UTF-8   
        for($i=0;$i<$dataNum;$i++){
          for($j=0;$j<$cellNum;$j++){
            $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j].($i+2), $manual_export[$i][$expCellName[$j][0]]);
          }             
        }
		$objPHPExcel->getActiveSheet()->setTitle("订单记录");  
		$objPHPExcel->createSheet();
		
        import("Org.Util.PHPExcel.IOFactory");
		
        header('pragma:public');
        header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$xlsTitle.'.xls"');
        header("Content-Disposition:attachment;filename=$fileName.xls");//attachment新窗口打印inline本窗口打印
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');  
        $objWriter->save('php://output'); 
        exit;   
    }
	
	
	/* 编辑活动 */
	public function Edit_activity(){
		$m_mall_content = M('mall_content');
		$m_mall_content_money = M('mall_content_money');
		$m_mall_content_img = M('mall_content_img');
		include_once 'upload.func.php';
		$map['id'] = I('param.id');
		//判断是否是ajax请求
		if(IS_POST){
			$value = I('param.value','','');
		
			 $pattern_img = '/<img (.+?)\/>/';
			 preg_match_all($pattern_img,$value,$matches_img);
			 
			 $pattern_src = '/src="(.+?)"/';
			foreach($matches_img[1] as $ii=>$vv){
				preg_match_all($pattern_src,$vv,$matches_src);
				$img_url = if_url($matches_src[1][0]);
				if($img_url){
					$matches_src_list_jiequ[] = cut_image($img_url);
					$matches_src_list[] = $img_url;
				}
				
			}
			$matches_src_str = implode(",",$matches_src_list);
			
			//获得数据
			$data = I();
			$data['url'] = $matches_src_str;
			$style = I('param.style');
			$data['style'] = implode(',',I('param.style'));
			$data['value'] = I('param.value','','');
			/* $data['uid'] = getUID(); */
			$data['time'] = time();
			$data['release_time'] = strtotime(I("param.release_time"));
			$data['ip'] = get_client_ip();
			$m_mall_content->where($map)->save($data);
				$delete_img['status'] = 1;
				$delete_img['type'] = 5;
				$delete_img['form_id'] = $map['id'];
				
				$save_img['status'] = 0;
				$save_result = $m_mall_content_img->where($delete_img)->save($save_img);
				
				#添加相册
				foreach($matches_src_list as $i=>$v){
					mall_img(5,$map['id'],trim($matches_src_list[$i],'.'));
				}
				#创建单曲与风格的关联  zyd_cms_style  
				add_style(3,$map['id'],$style); 
				#创建价格
				$begin_array = I('param.huodong_begin');
				$end_array = I('param.huodong_end');
				$money_array = I('param.huodong_money');
				$name_array = I('param.huodong_name');
				$number = I('param.number');
				foreach($begin_array as $i=>$v){
					$add_begin['begin_time'] = strtotime($begin_array[$i]);
					$add_begin['end_time'] = strtotime($end_array[$i]);
					$add_begin['goods_money'] = $money_array[$i];
					$add_begin['name'] = $name_array[$i];
					$add_begin['number'] = $number[$i];
					$add_begin['goods_id'] = $map['id'];	
					$m_mall_content_money->add($add_begin);
				}
			$this->success('编辑成功', U('Mall/User/activity'));
		}else{
			
			$map['type'] = get_mall_model_conf('MALL_ACTIVITY');
			#$map['status'] = array('in','2,4');
			$map['uid'] = $_SESSION['u_id'];
			$data = $m_mall_content->where($map)->find();
			
			#查询价格
			$money_map['goods_id'] = $data['id'];
			$money_list = $m_mall_content_money->where($money_map)->select();
			
			#流派风格
			$style_list = gettypes();
			
			$style_list = if_style($style_list,$data['style']);
			#dump($style_list);die;
			
			$this->assign('data',$data);
			$this->assign('style_list',$style_list);
			$this->assign('money_list',$money_list);
			$this->display();
		}
	}
	
	
	
}